package com.roc.service;

import java.util.List;
import java.util.Map;

import com.roc.bean.TermBean;
import com.roc.dao.DaoException;
import com.roc.pojo.Operators;
import com.roc.pojo.TPosAgent;
import com.roc.pojo.TPosInfo;
import com.roc.pojo.TblDictionaryItem;
import com.roc.pojo.TblDictionaryLayerItem;
import com.roc.pojo.TblTermInf;
import com.roc.pojo.TermInfo;
import com.roc.pojo.TermInfoTmp;
import com.roc.pojo.Termapply;
import com.roc.pojo.TidRecord;
import com.roc.pojo.YjPosAgent;
import com.roc.pojo.YjPosInfo;

/**
 * 
 * @author 陈锴
 * 
 * 终端管理
 * 
 * 2014-08-13
 *
 */

public interface ITerminalService {

	Termapply queryTerminal(long id) throws ServiceException;
	
	//添加终端 
	void saveTerminal(List<TermBean> termBeanList,String account,String mid) throws ServiceException;
	
	//终端流水号绑定
	void bindingTerminalSn(YjPosInfo yjPos,String accountNo) throws ServiceException;
	//查询终端信息
	List<TermBean> queryByMid(String merchantNo)throws ServiceException;
	
	//终端关联表
	TermInfo queryTermInfo(String tid) throws ServiceException;
	
	//POS表
	YjPosInfo queryYjPosInfo(String sum,String posBrandCode) throws ServiceException;
	
	//云商宝POS表
	TPosInfo queryYsbYjPosInfo(String sum,String posBrandCode) throws ServiceException;
	/**
	 * 开通终端
	 * @param accountNo
	 * @param tid
	 * @param mid
	 * @param serialNum
	 * @param remark
	 * @throws ServiceException
	 */
	public void clearTermInfo(String accountNo,String tid,String mid,String serialNum,String remark) throws ServiceException;
	
	//流水号导入
	void saveYjPosInfo(List<YjPosInfo> posinfo,YjPosInfo pos,String accountNo) throws ServiceException;
	
	//分配终端
	int  SerialNumTer(List<String> terList,Operators op,String code) throws ServiceException;
	
	/**
	 * 批量分配终端
	 * @param agentList
	 * @param op
	 * @param pos
	 * @param code
	 * @return
	 * @throws ServiceException
	 */
	List<YjPosAgent> SerialNumTerByForExecl(List<YjPosAgent> agentList, Operators op,YjPosInfo pos,Operators toOperator) throws ServiceException;
	
	/**
	 * 批量终端分配
	 * @param agentList
	 * @param op
	 * @param pos
	 * @param toOperator
	 * @return
	 * @throws ServiceException
	 */
	public Map<String,List<YjPosAgent>> getSeriaNumListForExeclMap(List<YjPosAgent> agentList, Operators op,YjPosInfo pos,Operators toOperator) throws ServiceException;
	
	/**
	 * 批量导入终端序列号
	 */
	public List<YjPosInfo> batchSaveSeriaNum(List<YjPosInfo> posinfo,YjPosInfo pos,Operators operators) throws ServiceException;

	/**
	 * 批量导入云商宝SN序列号
	 */
	public List<TPosInfo> batchSaveYsbSeriaNum(List<TPosInfo> posinfo,TPosInfo pos,Operators operators) throws ServiceException;
	
	public List<Long> getOpertorsIdsTreeById(Long id) throws ServiceException;
	
	public int terminalAllotRecallBySN(List<String> serialList,Operators operators,Operators agent ) throws ServiceException;
	
	public List getPosInfosForBatchRecall(String seriaNum,String orgCode,Long agentId, String posBrand,String posType, String posName,Operators op) throws ServiceException;
	
	public List<TermBean> queryTermChangeByMid(String merchantNo)throws ServiceException;

	
	/**
	 * 通过商户号修改所有的终端状态
	 * @param mid
	 * @param flag
	 * @param accountNo
	 * @return
	 * @throws ServiceException
	 */
	public int updateEstidinfoFlag(String mid,int flag,String accountNo) throws ServiceException;
	
	/**
	 * 终端序列号解除绑定
	 * @param yjPos
	 * @param accountNo
	 * @throws ServiceException
	 */
	public void unbindingTerminalSn(YjPosInfo yjPos,String accountNo,String mid,long agentId) throws ServiceException;
	
	
	/**
	 * 终端序列号重新绑定
	 * @param mid
	 * @param tid
	 * @param serialNum
	 * @param accountNo
	 * @throws ServiceException
	 */
	public void reBindingTerminalSn(String mid,String tid,String serialNum,String posBrandCode,String accountNo,long agentId) throws ServiceException;
	
	/**
	 * 更新出库状态
	 * @param serialNum
	 * @param agentId
	 * @param flag
	 * @return
	 * @throws ServiceException
	 */
	public int updateAgentIsUsed(String serialNum,long agentId,String flag)throws ServiceException;
	
	public void insertTermInfoTmpByTid(String tid,String accounNo,String mid)throws ServiceException;
	public  List<TermInfoTmp> queryTermInfoTmpByMid(String mid)throws ServiceException;
	public void delTermInfoTmpByMid(String accounNo,String mid)throws ServiceException;
	public  List<TermInfoTmp> queryTermNULLTmpByMid(String mid)throws ServiceException;
	
	/**
	 * 保存终端记录
	 * @param tid
	 * @throws ServiceException
	 */
	public void saveTidRecord(TidRecord tid) throws ServiceException;
	

	/**
	 * 查询型号
	 * @param tid
	 * @throws ServiceException
	 */
	public List<Map<String, Object>> selModelItemByType(TblDictionaryLayerItem item) throws ServiceException;
	

	/**
	 * 查询品牌
	 * @param tid
	 * @throws ServiceException
	 */
	public Map<String,String> selBrandItemByType(TblDictionaryItem item) throws ServiceException;
	
	/**
	 * 查询类型
	 * @param tid
	 * @throws ServiceException
	 */
	public Map<String,String> selTypeItemByType(TblDictionaryItem item) throws ServiceException;
	/**
	 * 分配终端SN
	 * @param tblTermInf
	 */
	public void setSerialNumber(String termID,String merchtNo,YjPosInfo yjPos,String orgCode)throws ServiceException;
	/**
	 * 修改SN状态yj_pos_agent
	 * @param serialNum
	 * @throws DaoException
	 */
	public void updateSerialNumberStatus(String serialNum,String posBrandCode,long agentid,String accountNo,String tid)throws ServiceException;
	
	/**
	 * 修改SN状态2  yj_pos_info
	 * @param serialNum
	 * @throws DaoException
	 */
	public void updateSerialNumberStatus2(String serialNum,String posBrandCode,String mid,String tid)throws ServiceException;
	/**
	 * 查询终端信息
	 * @param mid
	 * @return
	 * @throws DaoException
	 */
	TblTermInf queryTermInfopart(String tid,String mid) throws ServiceException;
	/**
	 * 绑定终端时将现有序列号和默认序列号存入临时表yj_sn_info、待解绑时使用
	 * @param termInf
	 * @param newCode
	 * @throws ServiceException
	 */
	public void bindTermTmp(TblTermInf termInf,String newCode,String posBrandCode)throws ServiceException;
	/**
	 * 绑定终端时向系统日志表插入绑定信息
	 * @param serialNum
	 * @param accountNo
	 * @param tid
	 * @throws ServiceException
	 */
	public void sysLogRecord(String serialNum,String posBrandCode,String accountNo,String tid,String mid)throws ServiceException;
	
	/**
	 * 删除 sn 信息
	 * @param serialNum
	 * @param accountNo
	 * @param tid
	 * @throws ServiceException
	 */
	public void delTerminalPosSNInfo(String [] sNum,Operators op)throws ServiceException;

	/**
	 * 撤回 sn 信息
	 * @param serialNum
	 * @param accountNo
	 * @param tid
	 * @throws ServiceException
	 */
	public List<String> revTerminalPosSNInfo(String [] sNum,Operators op)throws ServiceException;
	
	/**
	 * 终端统计  分公司获取直属代理
	 * @param superAgentId
	 * @return
	 */
	public List<Map<String, Object>> superAgentId(String superAgentId);
	
	/**
	 *  解绑终端并修改参数
	 * @param serialNum_origin
	 * @param serialNum_new
	 * @param mid
	 * @param tid
	 * @throws DaoException
	 */
	public void unbindTerminal(String serialNum_new,String posBrandCode,String mid,String tid,String accountNo)throws ServiceException;
	/**
	 * 绑定终端并修改参数
	 * @param termInf
	 * @param yjPos
	 * @param serialNumer
	 * @param op
	 * @throws ServiceException
	 */
	public String bindTerminal(String mid,String tid,String serialNumer,String posBrandCode,Operators currentOpr,Operators loginOpr)throws ServiceException;
	/**
	 * 解绑终端重置秘钥
	 * @return
	 * @throws ServiceException
	 */
	public int unbindTerminalTkey(String mid,String tid)throws ServiceException;	
	public int unbindTerminalWkey(String mid,String tid)throws ServiceException;

	/**
	 * 解绑云商宝终端重置秘钥
	 * @return
	 * @throws ServiceException
	 */
	public int unbindYsbTerminalTkey(String mid,String tid)throws ServiceException;	
	public int unbindYsbTerminalWkey(String mid,String tid)throws ServiceException;

	
	int ysbSerialNumTer(List<String> terList, Operators op, String code,String flag) throws ServiceException;

	Map<String, List<TPosAgent>> getYsbSeriaNumListForExeclMap(List<TPosAgent> agentList, Operators op, TPosInfo pos,
			Operators toOperators,String flag) throws ServiceException;

	List<TPosAgent> YsbSerialNumTerByForExecl(List<TPosAgent> agentList, Operators op, TPosInfo pos,
			Operators toOperators,String flag) throws ServiceException;

	
	/**
	 * 云商宝解绑终端并修改参数
	 * @param serialNum_origin
	 * @param serialNum_new
	 * @param mid
	 * @param tid
	 * @throws DaoException
	 */
	public void unbindYsbTerminal(String serialNum_new,String posBrandCode,String mid,String tid,String accountNo)throws ServiceException;

	/**
	 * 云商宝 撤回 sn 信息
	 * @param serialNum
	 * @param accountNo
	 * @param tid
	 * @throws ServiceException
	 */
	public List<String> revYsbTerminalPosSNInfo(TPosAgent tPosAgent,Operators op)throws ServiceException;

	/**
	 * 通过商户号和终端号查询直属代理商id
	 * @param tPosInfo
	 * @return
	 * @throws ServiceException
	 */
	String queryYsbDirAgentByTerm(TPosInfo tPosInfo) throws ServiceException;

	/**
	 * 换机
	 * @param serialNum_new
	 * @param posBrandCode_new
	 * @param posModelNo_new
	 * @param mid
	 * @param tid
	 * @param dirAgentId 直属代理商id
	 * @param loginOpr
	 * @throws ServiceException
	 */
	String replaceYsbTerminal(String serialNum_new,String posBrandCode_new,String posModelNo_new, String mid, String tid,String dirAgentId,Operators loginOpr)throws ServiceException;
}
